
/*
 * Author: Ken YANG <spng.yang@gmail.com>
 *
 * Some basic functions wrapper, including process 
 * management, memory mamagement, and etc.
 *
 * */

#if !defined (_HAVE_FUNC_BASIC_H)
#define _HAVE_FUNC_BASIC_H 1

#include <unistd.h>
#include <sys/types.h>
#include "error.h"
#include <signal.h>
#include <sys/wait.h>
#include <sys/time.h>
#include <sys/select.h>

#define _GNU_SOURCE
#include <getopt.h>

#define max(a,b) ((a)>(b) ? (a):(b))
#define min(a,b) ((a)<(b) ? (a):(b))

typedef void Sigfunc (int);



/* Wrapper functions, including error handle */
pid_t Fork(void);
void *Malloc(size_t size);
void *Calloc(size_t n, size_t size);
int Fcntl(int fd, int cmd, int args);


/* 
 * Simulate the semanic of old "signal()", using 
 * POSIX sigaction()
 *
 * */
Sigfunc *signal(int signo, Sigfunc *func);
/* Above's wrapper */
Sigfunc *Signal(int signo, Sigfunc *func);

/* SIGCHLD signal handle */
void wait_chld(int signo);


/* Select wrapper */
int Select(int maxfdpl, fd_set *readset, fd_set *writeset,
		fd_set *exceptset, const struct timeval *timeout);


#endif


